import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_widget/viewmodel/mvvm.dart';

// ignore: import_of_legacy_library_into_null_safe
import 'package:provider/provider.dart';
import 'provider/count_provider.dart';
import 'provider/color_them_provider.dart';
import "package:get/get.dart";
import "package:flutter_widget/custom/custom_card.dart";
import "package:flutter_widget/category/flutter_plugin_page.dart";
import "package:flutter_widget/category/flutter_widget_page.dart";
import "package:flutter_widget/category/flutter_exercise_page.dart";

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await SystemChrome.setPreferredOrientations(
    [
      DeviceOrientation.portraitUp, // 竖屏 Portrait 模式
      DeviceOrientation.portraitDown,
      // DeviceOrientation.landscapeLeft, // 横屏 Landscape 模式
      // DeviceOrientation.landscapeRight,
    ],
  );
  // 纯净式状态栏
  SystemUiOverlayStyle style = const SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,

    ///这是设置状态栏的图标和字体的颜色
    ///Brightness.light  一般都是显示为白色
    ///Brightness.dark 一般都是显示为黑色
    statusBarIconBrightness: Brightness.light,
  );

  SystemChrome.setSystemUIOverlayStyle(style);
  runApp(
    GetMaterialApp(
      debugShowCheckedModeBanner: false,
      home: MultiProvider(providers: [
        ChangeNotifierProvider(
          create: (_) => CountProvider(),
        ),
        ChangeNotifierProvider(
          create: (_) => MvvmProvider(),
        ),
        ChangeNotifierProvider(
          create: (_) => ColorThemeProvider(),
        ),
      ], child: const MyApp()),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final MaterialColor color = Provider.of<ColorThemeProvider>(context).color;
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData.light().copyWith(
        // primarySwatch: color,
        primaryColor: color,
        buttonTheme: ButtonThemeData(
            buttonColor: color, textTheme: ButtonTextTheme.normal),
        highlightColor: const Color.fromRGBO(255, 255, 255, 0),
        splashColor: Colors.white70,
        // ignore: deprecated_member_use
        accentColor: const Color.fromRGBO(3, 54, 255, 1.0),
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final List<Map> customCardList = [
    {
      'name': 'flutter控件',
      "widget": const FlutterWidgetPage(name: 'flutter 控件'),
    },
    {
      'name': 'flutter 第三方插件',
      "widget": const FlutterPluginPage(name: 'flutter 第三方插件'), //返回的是需要跳转单页面
    },
    {
      'name': 'flutter 案列练习',
      "widget": const FlutterExercisePage(name: 'flutter 案列练习'), //返回的是需要跳转单页面
    },
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('flutter开发'),
      ),
      body: Column(
        children: customCardList
            .map(
              (e) => CustomCard(
                child: Text(e['name']),
                onPressed: () {
                  Navigator.of(context).push(
                    MaterialPageRoute(builder: (context) => e['widget']),
                  );
                },
              ),
            )
            .toList(),
      ),
    );
  }
}
